package com.wisdytech.linkdcs.equipLifeCycle.malfunction.service.impl;

import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.wisdytech.common.enums.MalfunctionComfirmEnum;
import com.wisdytech.common.enums.MalfunctionStatusEnum;
import com.wisdytech.common.exception.ServiceException;
import com.wisdytech.common.handler.BaseService;
import com.wisdytech.common.utils.BaseUtil;
import com.wisdytech.linkdcs.equipLifeCycle.malfunction.dao.IMConfirmRecordDao;
import com.wisdytech.linkdcs.equipLifeCycle.malfunction.model.MConfirmRecord;
import com.wisdytech.linkdcs.equipLifeCycle.malfunction.model.MalfunctionRecord;
import com.wisdytech.linkdcs.equipLifeCycle.malfunction.service.IMConfirmRecordService;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author dailibo
 * @since 2018-06-11
 */
@Service
@Transactional
public class MConfirmRecordServiceImpl extends BaseService<IMConfirmRecordDao, MConfirmRecord> implements IMConfirmRecordService {

	private Logger logger =LoggerFactory.getLogger(getClass());

	@Override
	public boolean confirmRecord(MConfirmRecord cRecord,String username) {
		//更新记录表
		String recordId =cRecord.getRecordId();
		MalfunctionRecord record=new MalfunctionRecord();
		record.setPkId(recordId);
		record.setUpdateUser(username);
		record.setUpdateDate(new Date());
		record.setFailureStatus(MalfunctionStatusEnum.ok.getCode());
		record.setFailureResult(cRecord.getFailureResult());
		
		
		//更新不成功
		if(!record.updateById()) {
			throw new ServiceException("故障处理更新记录失败");
		}
		cRecord.setPkId(BaseUtil.getUUID());
		
		
		return cRecord.insert();
	}

}
